package com.cn.wzq.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.cn.wzq.dao.IUserDao;
import com.cn.wzq.pojo.User;
import com.cn.wzq.service.IUserService;
@Service("userService")  
public class UserServiceImpl implements IUserService{
	@Resource(name="xxxx")   
    private IUserDao userD;
	@Override
	public User getUserById(int userId) {
		return this.userD.selectByPrimaryKey(String.valueOf(userId));
	}
	@Override
	public int insertUser(User u) {
		// TODO Auto-generated method stub
		return this.userD.insert(u);
	}
	@Override
	public int deleteUserById(String no) {
		// TODO Auto-generated method stub
		return this.userD.deleteByPrimaryKey(no);
	}
	@Override
	public int updateUserSelectived(User u) {
		// TODO Auto-generated method stub
		return this.userD.updateByPrimaryKeySelective(u);
	}
	
	

	@Override
	public void insertUser(List<User> users) { 
        for (int i = 0; i < users.size(); i++) {  
        	
            this.userD.insert(users.get(i));
        	 
        }  
	}
	@Override
	public List<User> getUserByContidion(String pageSize, String page) {
		User user = new User();
		
		int start = Integer.valueOf(page)-1 ;
		if(start < 0){
			start = 0;
		}
		start = start * Integer.valueOf(pageSize);
		
		user.setOffset(start);
		user.setPageSize(Integer.valueOf(pageSize));		
		return this.userD.getUserByContidion(user);
	}

}
